package com.ruoyi.business.controller;

import com.ruoyi.business.domain.THomeworkStu;
import com.ruoyi.business.domain.bo.HomeWorkStuBo;
import com.ruoyi.business.domain.vo.HomeWorkStuVo;
import com.ruoyi.business.domain.vo.THomeWorkStuVo;
import com.ruoyi.business.service.IHomeworkService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * 作业的控制器
 * @author 最爱喝兽奶
 * @create 2022/9/13
 **/
@RestController
@RequestMapping("/business/homeworkStu")
public class HomeworkStuController extends BaseController {

    @Autowired
    private IHomeworkService homeworkService;

    @ApiOperation("获取作业信息的列表")
    @GetMapping("/list")
    public AjaxResult list(HomeWorkStuBo bo) {
        TableDataInfo<HomeWorkStuVo> result = homeworkService.queryHomeworkByPage(bo);
        return AjaxResult.success(result);
    }

    @ApiOperation("根据传入id获取作业信息")
    @GetMapping("/{id}")
    public AjaxResult getHomework(@PathVariable("id") String id) throws ParseException {
        HomeWorkStuVo vo = homeworkService.getHomeworkById(id);
        return AjaxResult.success(vo);
    }

    @ApiOperation("新增作业信息")
    @PostMapping
    public AjaxResult add(@RequestBody HomeWorkStuBo bo) {
        homeworkService.insertHomeworkStu(bo);
        return AjaxResult.success();
    }

    @ApiOperation("修改作业信息")
    @PutMapping
    public AjaxResult edit(@RequestBody HomeWorkStuBo bo) {
        homeworkService.updateHomeworkStu(bo);
        return AjaxResult.success();
    }

    @ApiOperation("根据传入的id来删除作业信息")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") String id) {
        homeworkService.deleteHomeworkStuById(id);
        return AjaxResult.success();
    }

}
